package com.lzit.smart_canteen.repository;

import com.lzit.smart_canteen.domain.OrderItem;
import jakarta.persistence.criteria.CriteriaBuilder;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface OrderItemRepository extends JpaRepository<OrderItem, Integer> {
    //按用户ID查找订单Ite
    List<OrderItem> findOrderItemsByUid(Integer uid);

    @Transactional
    @Modifying
    void deleteOrderItemsByOid(String oid);
    @Transactional
    @Modifying
    @Query(value = "UPDATE t_order_item SET status=?1 WHERE oid=?2 ", nativeQuery = true)
    void updateStatusByOid(String status,String oid);

    List<OrderItem> findOrderItemsByOid(String oid);

    List<OrderItem> findOrderItemsByWindowAndStatus(Integer window,String status);
    List<OrderItem> findOrderItemsByOidAndStatus(String oid,String status);

    @Transactional
    @Modifying
    @Query(value = "UPDATE t_order_item SET status=?1 WHERE oid=?2 AND fid=?3", nativeQuery = true)
    void updateItemStatusByOidAndFid(String status,String oid,Integer fid);
}
